<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue 组件之属性传值</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <my-post v-for="post in posts" :key="post.id" :title="post.title" :published="post.published"></my-post>
    </div>
    <script>
        Vue.component('my-post', {
            // 使用props属性来接受外部数据
            props: ['title', 'published'],
            template: '<div><h3>{{title}}</h3><p>{{published}}</p></div>'
        })
        var app7 = new Vue({
            el: '#app',
            data: {
                posts: [
                    { id: 1, title: '标题1', published: '2020-5-11' },
                    { id: 2, title: '标题2', published: '2020-5-21' },
                    { id: 3, title: '标题3', published: '2020-5-13' },
                ]
            }
        })
    </script>
</body>

</html>
